<?php
	
namespace app\admin\model;

use app\common\tools\Strings;
use think\Config;
use think\Model;
use think\Db;
use think\Request;
use think\Session;

class Apply extends Model{
	
	//protected $autoCheckFields = false;
	
	public function getEmploy(){		
			
		$employs = Db::table('link_man')
			->join('education','link_man.link_man_id=education.link_man_id')
			->join('phone_contact','link_man.link_man_id=phone_contact.link_man_id')
			//->fetchSql(true)
			->paginate(3);
		
		return $employs;
		
	}
	
	public function getStatus(){
		
		return $status = Db::table('phone_contact')
			->field('contact_id,phone_res')
			->order('contact_id ASC')
			->select();
	}
	
	public function applyAdd(array $params){
		//var_dump($params);exit;
		$add = Db::table('phone_contact')						
			->insert([
            	'phone_res'      	=> $params['phone_res'],
            	'contact_remark'    => $params['contact_remark'],
        		]);
        		                        		
        return $add;
	}
	
	public function applyHistory(){
		
		$history = Db::table('phone_contact')
			->field('phone_res,contact_remark,contact_time')
			->order('contact_time DESC')
			->select();
		
		return $history;
	}
	
	public function getDetail(){
		
		$details = Db::table('link_man')
			->join('education','link_man.link_man_id=education.link_man_id')
			->join('phone_contact','link_man.link_man_id=phone_contact.link_man_id')		
			//->fetchSql(true)
			->select();
	}
	
	public function toEdit(){
				
		//$xxx = self::get($params['id']);

        /*if ($xxx === false) {
            $this->error = "文章不存在或者已删除！";

            return false;
        }*/

        /*if ($xxx->thumbnail != $params['xxx-thumbnail']) {
            Strings::deleteFile($xxx->thumbnail);
        }*/

        /*return $this->save([
            'category_id' => $params['category_id'],
            'title'       => $params['title'],
            'thumbnail'   => $params['aricle-thumbnail'],
            'description' => $params['description'],
            'keyword'     => $params['keyword'],
            'content'     => $params['content'],
            'status'      => isset($params['status']) ? $params['status'] : 0,
            'sort'        => $params['sort'],
        ], ['id' => $params['id']]);*/
	}
	
	public function toSave(){
		
		$add = Db::table('phone_contact')						
			->insert([
            	'phone_res'      	=> $params['phone_res'],
            	'contact_remark'    => $params['contact_remark'],
        		]);
        		                        		
        return $add;
	}
					
}
